<?
	include('conn.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PALER, JOHN EMISYL L.</title>
</head>


<script language="javascript">

	function chkall() {
		for(var i=0;i<document.frm2.txtcount.value;i++) {
				document.frm2.chk[i].checked=true;
		}
	}
	
	function Unchkall() {
		
		for(var i=0;i<document.frm2.txtcount.value;i++) {
			document.frm2.chk[i].checked=false;
		}
	
	}
	
	
	function validEdit() {
		
		var ret=false;
		
		for(var j=0;j<document.frm2.chk.length;j++) {
		
			if(document.frm2.chk[j].checked==true) {
				ret = true;	
			}
		}
		
		if(ret==false) {
			alert('No record selected!');
			return false;
		}else {
			
			document.getElementById("txtC").value="update";
			document.frm2.submit();
			return true;
		}
		
	}
	
	
</script>

   
     <form name="frm2" action="maincore.php" method="post">
     
   
    <table border="0" width="500">
    <tr>
    </tr>
    <tr>
    	<td>
        
			<table width="100%" border="1" cellspacing="0" cellpadding="0">
              <tr>

              	<td bgcolor="#CCCCCC" width="6%" align="left">
                	<!--<input type="checkbox"  name="checkall" onclick='chkall()' />!-->
                </td>
                <td bgcolor="#CCCCCC"  align="left"><b>STUDENT NAME</b></td>
                <td bgcolor="#CCCCCC"  align="left"><b>COURSE</b></td>

              </tr>
           <?
		   
if($_REQUEST['starting']=="") {
	 $starter=0;
}else {
	$starter=$_REQUEST['starting'];
}
		    	
$limitRec = 10;
$val = $starter + $limitRec;
$back = $starter - $limitRec; 
$next = $starter + $limitRec;   


//$sql=mysql_db_query("dbStudents","select * from tblstudents",$conn);
$sql=mysql_query("select * from tblstudents");

$numOfRec=mysql_num_rows($sql);

if($_GET['txtSearch'] <> "") {

	$find = $_GET['txtSearch'];
	$sql=mysql_db_query("dbStudents","SELECT `tblstudents`.`stud_name`,`tblstudents`.`stud_control`, `tblstudents`.`stud_name`,`tblstudents`.`stud_course`, `tblcourse`.`course_control`, `tblcourse`.`course_desc`
	FROM `tblstudents`LEFT JOIN `tblcourse` ON `tblstudents`.`stud_course` = `tblcourse`.`course_control` 
	where `stud_name` LIKE '%$find%' order by `stud_name` limit $starter,$limitRec",$conn);

}else {

	//$sql=mysql_db_query("dbStudents","SELECT `tblstudents`.`stud_control`, `tblstudents`.`stud_name`,`tblstudents`.`stud_course`, `tblcourse`.`course_control`, `tblcourse`.`course_desc`
	//FROM `tblstudents`LEFT JOIN `tblcourse` ON `tblstudents`.`stud_course` = `tblcourse`.`course_control` order by `stud_name` limit $starter,$limitRec",$conn);
       
    $sql=mysql_query("SELECT `tblstudents`.`stud_control`, `tblstudents`.`stud_name`,`tblstudents`.`stud_course`, `tblcourse`.`course_control`, `tblcourse`.`course_desc`
	FROM `tblstudents`LEFT JOIN `tblcourse` ON `tblstudents`.`stud_course` = `tblcourse`.`course_control` order by `stud_name` limit $starter,$limitRec",$conn);

}
		$ctr=0;
                var_dump($sql);
		while($field=mysql_fetch_array($sql)) {
		   ?> 
             
              <tr>
             
              	<td bgcolor="#CCCCCC">
                    &nbsp;<?  echo("<input type='Checkbox' id='chk' name='check[]' value=$field[stud_control] />" ); ?>
                    <?  ?>
                </td>
                
                <td align="left">&nbsp;<? echo("$field[stud_name]"); ?></td>
                <td align="left">&nbsp;<? echo("$field[course_desc]"); ?></td>
                
                
              </tr>
              	
       		<? $ctr++; } ?>
            <input type="hidden" name="txtCtr" id="txtC" value=""/>
            <input type="hidden" value="<? echo($ctr); ?>" name="txtcount" />
 
            </table>
     
            
            
      	</td>
      </tr>
      		
            <tr>
            	<td align="left">
                	Select: <input type="button" name="cmdcheck" value="A" onclick='chkall()' /><input type="button" name="cmdnone" value="N" onclick='Unchkall()' />
              		
                    
                    &nbsp;&nbsp;
                	  <input type="button" name="cmddelete" value="Delete" onclick="remove()" />
                      <input type="button" name="cmdedit" value="Edit" onclick="validEdit()" />
                     
                </td>
            </tr>
      
		</table>
 
</form>
	       <center>
         
            <?
			
			if($back >=0) {
				echo("<a href=index.php?starting=$back><b>PREV</b></a>");
			}
				
	
				$numPage=1;
				
				for($i=0; $i < $numOfRec; $i=$i+$limitRec){
					
				if($i <> $starter){
					
				echo "&nbsp;&nbsp;<a href='index.php?starting=$i'><font face='Verdana' size='2'>[$numPage]</font></a>&nbsp;&nbsp;";
				}
				else { 
					echo "<font face='Verdana' size='4' color='red'>[$numPage]</font>";
				} 
					$numPage=$numPage+1;
				}
			
			
				if($val < $numOfRec) {
					echo("<a href=index.php?starting=$next><b>NEXT</b></a>");
				}

			?>
            
            </center>
            
            
<body>
</body>
</html>
